import os

from services.vector_store import VectorStoreService
from utils.file_loader import load_documents
from utils.text_splitter import get_text_splitter


def ingest_documents():
    project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    data_dir = os.path.join(project_root, "data")
    # 加载文档
    print(f"项目根目录: {project_root}")
    print(f"数据目录: {data_dir}")
    print("2. 测试文档处理...")
    documents = load_documents(data_dir=data_dir)
    text_splitter = get_text_splitter()
    chunks = text_splitter.split_documents(documents)
    # 创建向量存储
    vector_service = VectorStoreService()
    vector_service.create_vector_store(chunks)
    print(f"已处理 {len(chunks)} 个文档块，向量存储已创建")

if __name__ == "__main__":
    ingest_documents()